package controllers;

import com.fasterxml.jackson.databind.JsonNode;
import dao.AppPush_Repository;
import play.data.FormFactory;
import play.libs.Json;
import play.libs.concurrent.HttpExecutionContext;
import play.mvc.Controller;
import play.mvc.Result;

import javax.inject.Inject;
import java.util.concurrent.CompletionStage;

public class AppPushController extends Controller {

    private final FormFactory formFactory;
    private final AppPush_Repository appPush_Repository;
    private final HttpExecutionContext ec;

    @Inject
    public AppPushController(FormFactory formFactory, AppPush_Repository appPush_Repository, HttpExecutionContext ec) {
        this.formFactory = formFactory;
        this.appPush_Repository = appPush_Repository;
        this.ec = ec;
    }

    public CompletionStage<Result> AppPush() {
        JsonNode json = request().body().asJson();
        String clientId = json.findPath("clientId").textValue();
        String token = json.findPath("token").textValue();
        String deptId=json.findPath("deptId").textValue();
        String mobile=json.findPath("mobile").textValue();
        return appPush_Repository.AppPush(clientId,token,deptId, mobile).thenApplyAsync(_getTruckList -> {
            return ok(Json.toJson(_getTruckList));
        }, ec.current());
    }

    public CompletionStage<Result> AppPush1() {
        JsonNode json = request().body().asJson();
        String clientId = json.findPath("clientId").textValue();
        String token = json.findPath("token").textValue();
        String deptId=json.findPath("deptId").textValue();
        String mobile=json.findPath("mobile").textValue();
        return appPush_Repository.AppPush1().thenApplyAsync(_getTruckList -> {
            return ok(Json.toJson(_getTruckList));
        }, ec.current());
    }
}
